// Sets up STATA										<--- NEEDS LOCAL ADJUSTMENT
*version 16.1
clear
clear mata
clear matrix
set more off, permanently
set matsize 11000
set max_memory 80g
*net set ado "N:\durable\shared\statamod\ado\plus"
*adopath + "N:\durable\shared\statamod\ado\plus"

*ssc install ftools
*ssc install reghdfe
*ssc install estout
*ssc install outreg2, replace

* Change directory for results 
cd "D:\Olivier\Documents\Stata" // replace with your directory

* Opens logfile
capture log close
log using COIN_immigration_reg.log, replace

display "$S_TIME  $S_DATE"

* Adapt with your years
/*global startyear 1994 
global otheryears 1995 1996 1997 1998 1999 ///
					2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 ///  					
					2010 2011 2012 2013 2014 2015 2016 2017 2018 2019
*/

global startyear 2010
global otheryears 2011 2012 2013
					
					
foreach i in $startyear {
		use "temp\est`i'.dta", clear 					
}
foreach i in $otheryears {
		append using "temp\est`i'.dta"
}

* NEW 2022-01--11
keep if nb_sample>=2 & nb_sample!=.
* END NEW

/* Small remarks on FE variables

* For the regressions part with 3D nuts3 geographical and 4D sector variables, we should be careful of 
* possible changes in nomenclatures. If you have such change, we would need to absorb an interaction between period and the given fixed effect.

*For instance : if the sector 4d variable changes in 2000 and 2010, you could create a period variable as such

    gen period_sec=1
    replace period_sec=2 if year>=2000
    replace period_sec=3 if year>=2010

* and in the regression with the sector variable, you would than replace abs(sector) with abs(sector#period_sec)
* So similarly for changes in nuts3 variable 
 
 * For the other regressions with Nuts1, Sector aggregated, Size of firms, I make the assumption 
 * that the aggregation level is high enough for categories to be constant throughout the period. 
 * If that's not the case and there's no roundabout, you proceed similarly.
*/

***********************************/
/*BEWARE APPLY EVENTUALLY ENCODE DECODE */ 

encode nuts1, gen(nuts1b)
drop nuts1 
rename nuts1b nuts1

encode sector_agg, gen(sector_aggb)
drop sector_agg
rename sector_aggb sector_agg
/*******************************/

egen s_nuts1=sum(s_weight), by(nuts1 year)
egen s_sec=sum(s_weight), by(sector_agg year)
egen s_sz=sum(s_weight), by(orgsize year)

****************************************
* NEW
* Now keep all workers !
* After we only need workplaces with top earners
* keep if f9010_w>0 * <= comment this line !
****************************************

gen f9010xf9010=f9010xf9010_sw/f9010_w if f9010_w>0
gen f9010xf0025=f9010xf0025_sw/f9010_w if f9010_w>0
gen f9010xf0075=f9010xf0075_sw/f9010_w if f9010_w>0

egen sf9010_w=sum(f9010_w), by(year)
gen f9010_wn=f9010_w/sf9010_w

egen sf9010_nuts1=sum(f9010_w), by(nuts1 year)
egen sf9010_sec=sum(f9010_w), by(sector_agg year)
egen sf9010_sz=sum(f9010_w), by(orgsize year)

gen f9010_nuts1=(sf9010_nuts1-f9010_w/f9010)/(s_nuts1-f9010_w/f9010)  
gen f9010_sec=(sf9010_sec-f9010_w/f9010)/(s_sec-f9010_w/f9010)  
gen f9010_sz=(sf9010_sz-f9010_w/f9010)/(s_sz-f9010_w/f9010)  

gen f9010xf9010_gap=abs(f9010xf9010-0.1)

egen sf9910_w=sum(f9910_w), by(year)
gen f9910_wn=f9910_w/sf9910_w

gen f9910xf9910=f9910xf9910_sw/f9910_w if f9910_w>0
gen f9910xf0025=f9910xf0025_sw/f9910_w if f9910_w>0
gen f9910xf0075=f9910xf0075_sw/f9910_w if f9910_w>0

egen sf9910_nuts1=sum(f9910_w), by(nuts1 year)
egen sf9910_sec=sum(f9910_w), by(sector_agg year)
egen sf9910_sz=sum(f9910_w), by(orgsize year)

gen f9910_nuts1=(sf9910_nuts1-f9910_w/f9910)/(s_nuts1-f9910_w/f9910)  
gen f9910_sec=(sf9910_sec-f9910_w/f9910)/(s_sec-f9910_w/f9910)
gen f9910_sz=(sf9910_sz-f9910_w/f9910)/(s_sz-f9910_w/f9910)

gen f9910xf9910_gap=abs(f9910xf9910-0.01)

sort est year
by est: gen l2nbwkrs=nbwkrs[_n-2]

gen empl_boom=(((nbwkrs-l2nbwkrs)/nbwkrs)>0.1 & l2nbwkrs!=.)*((nbwkrs-l2nbwkrs)>10 & l2nbwkrs!=.)
gen empl_crash=(((l2nbwkrs-nbwkrs)/nbwkrs)>0.1 & l2nbwkrs!=.)*((l2nbwkrs-nbwkrs)>10 & l2nbwkrs!=.)

gen lnnbwkrs=log(nbwkrs)


****************************************
* NEW (corrected)
by est: gen lnbwkrs=nbwkrs[_n-1]

gen lndnbwkrs_pos=(log(nbwkrs)-log(lnbwkrs))*((log(nbwkrs)-log(lnbwkrs))>=0)
replace lndnbwkrs_pos=log(nbwkrs) if lndnbwkrs_pos==.
bysort est(year): gen lnnbwkrs_cumpos=sum(lndnbwkrs_pos)

gen lndnbwkrs_neg=(log(nbwkrs)-log(lnbwkrs))*((log(nbwkrs)-log(lnbwkrs))<=0)
replace lndnbwkrs_neg=log(nbwkrs) if lndnbwkrs_neg==.
bysort est(year): gen lnnbwkrs_cumneg=sum(lndnbwkrs_neg)

* End 
****************************************

********************************************
* NEW *
gen lnwage_u=lnwage_mu_sw/s_weight
egen sy_lnwage_mu=sum(lnwage_mu_sw), by(year)
egen sy_weight=sum(s_weight), by(year)
gen lnwage_mu=lnwage_u-(sy_lnwage_mu/sy_weight)
*drop lnwage_u sy_lnwage_mu sy_weight

gen f0025xf0025=f0025xf0025_sw/f0025_w if f0025_w>0
egen sf0025_w=sum(f0025_w), by(year)
gen f0025_wn=f0025_w/sf0025_w

egen sf0025_nuts1=sum(f0025_w), by(nuts1 year)
egen sf0025_sec=sum(f0025_w), by(sector_agg year)
egen sf0025_sz=sum(f0025_w), by(orgsize year)

gen f0025_nuts1=(sf0025_nuts1-f0025_w/f0025)/(s_nuts1-f0025_w/f0025)  
gen f0025_sec=(sf0025_sec-f0025_w/f0025)/(s_sec-f0025_w/f0025)  
gen f0025_sz=(sf0025_sz-f0025_w/f0025)/(s_sz-f0025_w/f0025)  

gen f0025xf0025_gap=abs(f0025xf0025-0.25)

gen f0075_w=f0025_w+f2575_w
gen f0075=f0025+f2575

gen f0075xf0075=f0075xf0075_sw/f0075_w if f0075_w>0
egen sf0075_w=sum(f0075_w), by(year)
gen f0075_wn=f0075_w/sf0075_w


egen sf0075_nuts1=sum(f0075_w), by(nuts1 year)
egen sf0075_sec=sum(f0075_w), by(sector_agg year)
egen sf0075_sz=sum(f0075_w), by(orgsize year)

gen f0075_nuts1=(sf0075_nuts1-f0075_w/f0075)/(s_nuts1-f0075_w/f0075)  
gen f0075_sec=(sf0075_sec-f0075_w/f0075)/(s_sec-f0075_w/f0075)  
gen f0075_sz=(sf0075_sz-f0075_w/f0075)/(s_sz-f0075_w/f0075)  

gen f0075xf0075_gap=abs(f0075xf0075-0.75)

* ENDNEW *
********************************************


**************************************************
*                     Results 					 *
**************************************************
*Descriptives
estpost tabstat year f9010xf9010_sw f9010_w f9010 f9010xf9010 f9010xf9010_gap f9010xf0025 f9010xf0075 f9010_nuts1 f9010_sec f9010_sz nb_sample nbwkrs lnnbwkrs [aweight=f9010_w] if  f9010_w>0, statistics(n sum mean sd semean min max ) by(year)
eststo tabstat90
esttab tabstat90 using des90.csv,replace cell("year f9010xf9010_sw f9010_w f9010 f9010xf9010 f9010xf9010_gap f9010xf0025 f9010xf0075 f9010_nuts1 f9010_sec f9010_sz nb_sample nbwkrs lnnbwkrs") plain

estpost tabstat year f9910xf9910_sw f9910_w f9910 f9910xf9910 f9910xf9910_gap f9910xf0025 f9910xf0075 f9910_nuts1 f9910_sec f9910_sz nb_sample nbwkrs lnnbwkrs [aweight=f9910_w] if  f9910_w>0, statistics(n sum mean sd semean min max ) by(year)
eststo tabstat99
esttab tabstat99 using des99.csv,replace cell("year f9910xf9910_sw f9910_w f9910 f9910xf9910 f9910xf9910_gap f9910xf0025 f9910xf0075 f9910_nuts1 f9910_sec f9910_sz nb_sample nbwkrs lnnbwkrs") plain

estpost tabulate nuts1 [aweight=f9010_wn] if  f9010_wn>0
eststo summstat3
esttab summstat3 using freq_nuts1_90.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate sector_agg [aweight=f9010_wn] if  f9010_wn>0
eststo summstat4
esttab summstat4 using freq_sec_90.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate orgsize [aweight=f9010_wn] if  f9010_wn>0
eststo summstat5
esttab summstat5 using freq_sz_90.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate nuts1 [aweight=f9910_wn] if  f9910_wn>0
eststo summstat3
esttab summstat3 using freq_nuts1_99.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate sector_agg [aweight=f9910_wn] if  f9910_wn>0
eststo summstat4
esttab summstat4 using freq_sec_99.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate orgsize [aweight=f9910_wn] if  f9910_wn>0
eststo summstat5
esttab summstat5 using freq_sz_99.csv,replace cells("b pct") varlabels(`e(labels)') plain


******************************************
* NEW *
estpost tabstat year f0075xf0075_sw f0075_w f0075 f0075xf0075 f0075xf0075_gap f0075xf0075 f0075_nuts1 f0075_sec f0075_sz nb_sample nbwkrs lnnbwkrs [aweight=f0075_w] if  f0075_w>0, statistics(n sum mean sd semean min max ) by(year)
eststo tabstat75
esttab tabstat75 using des75.csv,replace cell("year f0075xf0075_sw f0075_w f0075 f0075xf0075 f0075xf0075_gap f0075xf0075 f0075_nuts1 f0075_sec f0075_sz nb_sample nbwkrs lnnbwkrs") plain

estpost tabstat year f0025xf0025_sw f0025_w f0025 f0025xf0025 f0025xf0025_gap f0025xf0025 f0025_nuts1 f0025_sec f0025_sz nb_sample nbwkrs lnnbwkrs [aweight=f0025_w] if  f0025_w>0, statistics(n sum mean sd semean min max ) by(year)
eststo tabstat25
esttab tabstat25 using des25.csv,replace cell("year f0025xf0025_sw f0025_w f0025 f0025xf0025 f0025xf0025_gap f0025xf0025 f0025_nuts1 f0025_sec f0025_sz nb_sample nbwkrs lnnbwkrs") plain

estpost tabulate nuts1 [aweight=f0075_wn] if  f0075_wn>0
eststo summstat3
esttab summstat3 using freq_nuts1_75.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate sector_agg [aweight=f0075_wn] if  f0075_wn>0
eststo summstat4
esttab summstat4 using freq_sec_75.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate orgsize [aweight=f0075_wn] if  f0075_wn>0
eststo summstat5
esttab summstat5 using freq_sz_75.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate nuts1 [aweight=f0025_wn] if  f0025_wn>0
eststo summstat3
esttab summstat3 using freq_nuts1_25.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate sector_agg [aweight=f0025_wn] if  f0025_wn>0
eststo summstat4
esttab summstat4 using freq_sec_25.csv,replace cells("b pct") varlabels(`e(labels)') plain

estpost tabulate orgsize [aweight=f0025_wn] if  f0025_wn>0
eststo summstat5
esttab summstat5 using freq_sz_25.csv,replace cells("b pct") varlabels(`e(labels)') plain
* END NEW
******************************************


* Regressions

* TOp 10% isolation
reg f9010xf9010 year [aw=f9010_wn] if  f9010_wn>0, cluster(est)  
outreg2 using out90.xls, replace ctitle(Base) word excel label 

reg f9010xf9010 year i.nuts1 [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(Nuts1 FE) addtext(Nuts1 FE, YES) word excel label

reg f9010xf9010 year i.sector_agg [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(sector_agg FE) addtext(sector_agg FE, YES) word excel label

reg f9010xf9010 year i.orgsize [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(size FE) addtext(Orgsize FE, YES) word excel label

reg f9010xf9010 year i.nuts1 i.nuts1#c.f9010_nuts1 [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(Nuts1 exposure) addtext(Nuts1 FE, YES) word excel label

reg f9010xf9010 year i.nuts1 i.nuts1#c.f9010_nuts1 i.nuts1#c.year [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(Nuts1 variation) addtext(Nuts1 FE, YES) word excel label

reg f9010xf9010 year i.sector_agg i.sector_agg#c.f9010_sec [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(sector_agg exposure) addtext(sector_agg FE, YES) word excel label

reg f9010xf9010 year i.sector_agg i.sector_agg#c.f9010_sec i.sector_agg#c.year [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(sector_agg variation) addtext(sector_agg FE, YES) word excel label

reg f9010xf9010 year i.orgsize i.orgsize#c.f9010_sz [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(size exposure) addtext(Orgsize FE, YES) word excel label

reg f9010xf9010 year i.orgsize i.orgsize#c.f9010_sz i.orgsize#c.year [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(size variation) addtext(Orgsize FE, YES) word excel label

reg f9010xf9010 year i.nuts1 i.sector_agg i.orgsize [aw=f9010_wn] if  f9010_wn>0, cluster(est) 
outreg2 using out90.xls, append ctitle(3 gross FE) addtext(Nuts1 FE, YES, sector_agg FE, YES, Orgsize FE, YES) word excel label

reg f9010xf9010 year i.nuts1 i.nuts1#c.f9010_nuts1 i.sector_agg i.sector_agg#c.f9010_sec ///
	i.orgsize i.orgsize#c.f9010_sz [aw=f9010_wn] if  f9010_wn>0, cluster(est)  
outreg2 using out90.xls, append ctitle(3 gross exp) addtext(Nuts1 FE, YES, sector_agg FE, YES, Orgsize FE, YES) word excel label

reghdfe f9010xf9010 year [aw=f9010_wn] if  f9010_wn>0, abs(nuts3) cluster(est) 
outreg2 using out90.xls, append ctitle(nuts3 FE) addtext(Nuts3 FE, YES) word excel label

reghdfe f9010xf9010 year [aw=f9010_wn] if  f9010_wn>0, abs(sector) cluster(est) 
outreg2 using out90.xls, append ctitle(4D sec FE) addtext(4D sector FE, YES) word excel label

reghdfe f9010xf9010 year [aw=f9010_wn] if  f9010_wn>0, abs(est) cluster(est) 
outreg2 using out90.xls, append ctitle(est FE) addtext(est FE, YES) word excel label

reghdfe f9010xf9010 year lnnbwkrs [aw=f9010_wn] if  f9010_wn>0, abs(est) cluster(est) 
outreg2 using out90.xls, append ctitle(size +est FE) addtext(est FE, YES) word excel label

********************************
*NEW*
reghdfe f9010xf9010 year lnnbwkrs_cumpos lnnbwkrs_cumneg [aw=f9010_wn] if  f9010_wn>0, abs(est) cluster(est) 
outreg2 using out90.xls, append ctitle(asym size +est FE) addtext(est FE, YES) word excel label

reghdfe f9010xf9010 year lnnbwkrs lnnbwkrs_cumneg [aw=f9010_wn] if  f9010_wn>0, abs(est) cluster(est) 
outreg2 using out90.xls, append ctitle(asym size 2 +est FE) addtext(est FE, YES) word excel label

reghdfe f9010xf9010 year lnwage_mu [aw=f9010_wn] if  f9010_wn>0, abs(est) cluster(est) 
outreg2 using out90.xls, append ctitle(wage+est FE) addtext(est FE, YES) word excel label

reghdfe f9010xf9010 year lnnbwkrs lnwage_mu [aw=f9010_wn] if  f9010_wn>0, abs(est) cluster(est) 
outreg2 using out90.xls, append ctitle(size+wage+est FE) addtext(est FE, YES) word excel label
* End New
********************************

reghdfe f9010xf9010 year empl_boom empl_crash [aw=f9010_wn] if  f9010_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est) cluster(est) 
outreg2 using out90.xls, append ctitle(boom crash +est FE) addtext(est FE, YES) word excel label

reghdfe f9010xf9010 lnnbwkrs [aw=f9010_wn] if  f9010_wn>0, abs(est year) cluster(est) 
outreg2 using out90.xls, append ctitle(size +est year FE) addtext(est FE, YES) word excel label

reghdfe f9010xf9010 empl_boom empl_crash [aw=f9010_wn] if  f9010_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est year) cluster(est) 
outreg2 using out90.xls, append ctitle(boom crash +est year FE) addtext(est FE, YES) word excel label

reghdfe f9010xf9010_gap lnnbwkrs [aw=f9010_wn] if  f9010_wn>0, abs(est year) cluster(est) 
outreg2 using out90.xls, append ctitle(gap size +est year FE) addtext(est FE, YES) word excel label

reghdfe f9010xf9010_gap empl_boom empl_crash [aw=f9010_wn] if  f9010_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est year) cluster(est) 
outreg2 using out90.xls, append ctitle(gap boom crash +est year FE) addtext(est FE, YES) word excel label


* TOp 1% isolation
reg f9910xf9910 year [aw=f9910_wn] if  f9910_wn>0, cluster(est)  
outreg2 using out99.xls, replace ctitle(Base) word excel label 

reg f9910xf9910 year i.nuts1 [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(Nuts1 FE) addtext(Nuts1 FE, YES) word excel label

reg f9910xf9910 year i.sector_agg [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(sector_agg FE) addtext(sector_agg FE, YES) word excel label

reg f9910xf9910 year i.orgsize [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(size FE) addtext(Orgsize FE, YES) word excel label

reg f9910xf9910 year i.nuts1 i.nuts1#c.f9910_nuts1 [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(Nuts1 exposure) addtext(Nuts1 FE, YES) word excel label

reg f9910xf9910 year i.nuts1 i.nuts1#c.f9910_nuts1 i.nuts1#c.year [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(Nuts1 variation) addtext(Nuts1 FE, YES) word excel label

reg f9910xf9910 year i.sector_agg i.sector_agg#c.f9910_sec [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(sector_agg exposure) addtext(sector_agg FE, YES) word excel label

reg f9910xf9910 year i.sector_agg i.sector_agg#c.f9910_sec i.sector_agg#c.year [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(sector_agg variation) addtext(sector_agg FE, YES) word excel label

reg f9910xf9910 year i.orgsize i.orgsize#c.f9910_sz [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(size exposure) addtext(Orgsize FE, YES) word excel label

reg f9910xf9910 year i.orgsize i.orgsize#c.f9910_sz i.orgsize#c.year [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(size variation) addtext(Orgsize FE, YES) word excel label

reg f9910xf9910 year i.nuts1 i.sector_agg i.orgsize [aw=f9910_wn] if  f9910_wn>0, cluster(est) 
outreg2 using out99.xls, append ctitle(3 gross FE) addtext(Nuts1 FE, YES, sector_agg FE, YES, Orgsize FE, YES) word excel label

reg f9910xf9910 year i.nuts1 i.nuts1#c.f9910_nuts1 i.sector_agg i.sector_agg#c.f9910_sec ///
	i.orgsize i.orgsize#c.f9910_sz [aw=f9910_wn] if  f9910_wn>0, cluster(est)  
outreg2 using out99.xls, append ctitle(3 gross exp) addtext(Nuts1 FE, YES, sector_agg FE, YES, Orgsize FE, YES) word excel label

reghdfe f9910xf9910 year [aw=f9910_wn] if  f9910_wn>0, abs(nuts3) cluster(est) 
outreg2 using out99.xls, append ctitle(nuts3 FE) addtext(Nuts3 FE, YES) word excel label

reghdfe f9910xf9910 year [aw=f9910_wn] if  f9910_wn>0, abs(sector) cluster(est) 
outreg2 using out99.xls, append ctitle(4D sec FE) addtext(4D sector FE, YES) word excel label

reghdfe f9910xf9910 year [aw=f9910_wn] if  f9910_wn>0, abs(est) cluster(est) 
outreg2 using out99.xls, append ctitle(est FE) addtext(est FE, YES) word excel label

reghdfe f9910xf9910 year lnnbwkrs [aw=f9910_wn] if  f9910_wn>0, abs(est) cluster(est) 
outreg2 using out99.xls, append ctitle(size +est FE) addtext(est FE, YES) word excel label

********************************
*NEW*
reghdfe f9910xf9910 year lnnbwkrs_cumpos lnnbwkrs_cumneg [aw=f9910_wn] if  f9910_wn>0, abs(est) cluster(est) 
outreg2 using out99.xls, append ctitle(asym size +est FE) addtext(est FE, YES) word excel label

reghdfe f9910xf9910 year lnnbwkrs lnnbwkrs_cumneg [aw=f9910_wn] if  f9910_wn>0, abs(est) cluster(est) 
outreg2 using out99.xls, append ctitle(asym size2 +est FE) addtext(est FE, YES) word excel label

reghdfe f9910xf9910 year lnwage_mu [aw=f9910_wn] if  f9910_wn>0, abs(est) cluster(est) 
outreg2 using out99.xls, append ctitle(wage+est FE) addtext(est FE, YES) word excel label

reghdfe f9910xf9910 year lnnbwkrs lnwage_mu [aw=f9910_wn] if  f9910_wn>0, abs(est) cluster(est) 
outreg2 using out99.xls, append ctitle(size+wage+est FE) addtext(est FE, YES) word excel label
* End new *
********************************

reghdfe f9910xf9910 year empl_boom empl_crash [aw=f9910_wn] if  f9910_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est) cluster(est) 
outreg2 using out99.xls, append ctitle(boom crash +est FE) addtext(est FE, YES) word excel label

reghdfe f9910xf9910 lnnbwkrs [aw=f9910_wn] if  f9910_wn>0, abs(est year) cluster(est) 
outreg2 using out99.xls, append ctitle(size +est year FE) addtext(est FE, YES) word excel label

reghdfe f9910xf9910 empl_boom empl_crash [aw=f9910_wn] if  f9910_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est year) cluster(est) 
outreg2 using out99.xls, append ctitle(boom crash +est year FE) addtext(est FE, YES) word excel label

reghdfe f9910xf9910_gap lnnbwkrs [aw=f9910_wn] if  f9910_wn>0, abs(est year) cluster(est) 
outreg2 using out99.xls, append ctitle(gap size +est year FE) addtext(est FE, YES) word excel label

reghdfe f9910xf9910_gap empl_boom empl_crash [aw=f9910_wn] if  f9910_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est year) cluster(est) 
outreg2 using out99.xls, append ctitle(gap boom crash +est year FE) addtext(est FE, YES) word excel label




********************************
*NEW*

* Bottom 25% isolation
reg f0025xf0025 year [aw=f0025_wn] if  f0025_wn>0, cluster(est)  
outreg2 using out25.xls, replace ctitle(Base) word excel label 

reg f0025xf0025 year i.nuts1 [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(Nuts1 FE) addtext(Nuts1 FE, YES) word excel label

reg f0025xf0025 year i.sector_agg [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(sector_agg FE) addtext(sector_agg FE, YES) word excel label

reg f0025xf0025 year i.orgsize [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(size FE) addtext(Orgsize FE, YES) word excel label

reg f0025xf0025 year i.nuts1 i.nuts1#c.f0025_nuts1 [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(Nuts1 exposure) addtext(Nuts1 FE, YES) word excel label

reg f0025xf0025 year i.nuts1 i.nuts1#c.f0025_nuts1 i.nuts1#c.year [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(Nuts1 variation) addtext(Nuts1 FE, YES) word excel label

reg f0025xf0025 year i.sector_agg i.sector_agg#c.f0025_sec [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(sector_agg exposure) addtext(sector_agg FE, YES) word excel label

reg f0025xf0025 year i.sector_agg i.sector_agg#c.f0025_sec i.sector_agg#c.year [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(sector_agg variation) addtext(sector_agg FE, YES) word excel label

reg f0025xf0025 year i.orgsize i.orgsize#c.f0025_sz [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(size exposure) addtext(Orgsize FE, YES) word excel label

reg f0025xf0025 year i.orgsize i.orgsize#c.f0025_sz i.orgsize#c.year [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(size variation) addtext(Orgsize FE, YES) word excel label

reg f0025xf0025 year i.nuts1 i.sector_agg i.orgsize [aw=f0025_wn] if  f0025_wn>0, cluster(est) 
outreg2 using out25.xls, append ctitle(3 gross FE) addtext(Nuts1 FE, YES, sector_agg FE, YES, Orgsize FE, YES) word excel label

reg f0025xf0025 year i.nuts1 i.nuts1#c.f0025_nuts1 i.sector_agg i.sector_agg#c.f0025_sec ///
	i.orgsize i.orgsize#c.f0025_sz [aw=f0025_wn] if  f0025_wn>0, cluster(est)  
outreg2 using out25.xls, append ctitle(3 gross exp) addtext(Nuts1 FE, YES, sector_agg FE, YES, Orgsize FE, YES) word excel label

reghdfe f0025xf0025 year [aw=f0025_wn] if  f0025_wn>0, abs(nuts3) cluster(est) 
outreg2 using out25.xls, append ctitle(nuts3 FE) addtext(Nuts3 FE, YES) word excel label

reghdfe f0025xf0025 year [aw=f0025_wn] if  f0025_wn>0, abs(sector) cluster(est) 
outreg2 using out25.xls, append ctitle(4D sec FE) addtext(4D sector FE, YES) word excel label

reghdfe f0025xf0025 year [aw=f0025_wn] if  f0025_wn>0, abs(est) cluster(est) 
outreg2 using out25.xls, append ctitle(est FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025 year lnnbwkrs [aw=f0025_wn] if  f0025_wn>0, abs(est) cluster(est) 
outreg2 using out25.xls, append ctitle(size +est FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025 year lnnbwkrs_cumpos lnnbwkrs_cumneg [aw=f0025_wn] if  f0025_wn>0, abs(est) cluster(est) 
outreg2 using out25.xls, append ctitle(asym size +est FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025 year lnnbwkrs lnnbwkrs_cumneg [aw=f0025_wn] if  f0025_wn>0, abs(est) cluster(est) 
outreg2 using out25.xls, append ctitle(asym size2 +est FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025 year lnwage_mu [aw=f0025_wn] if  f0025_wn>0, abs(est) cluster(est) 
outreg2 using out25.xls, append ctitle(wage+est FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025 year lnnbwkrs lnwage_mu [aw=f0025_wn] if  f0025_wn>0, abs(est) cluster(est) 
outreg2 using out25.xls, append ctitle(size+wage+est FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025 year empl_boom empl_crash [aw=f0025_wn] if  f0025_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est) cluster(est) 
outreg2 using out25.xls, append ctitle(boom crash +est FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025 lnnbwkrs [aw=f0025_wn] if  f0025_wn>0, abs(est year) cluster(est) 
outreg2 using out25.xls, append ctitle(size +est year FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025 empl_boom empl_crash [aw=f0025_wn] if  f0025_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est year) cluster(est) 
outreg2 using out25.xls, append ctitle(boom crash +est year FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025_gap lnnbwkrs [aw=f0025_wn] if  f0025_wn>0, abs(est year) cluster(est) 
outreg2 using out25.xls, append ctitle(gap size +est year FE) addtext(est FE, YES) word excel label

reghdfe f0025xf0025_gap empl_boom empl_crash [aw=f0025_wn] if  f0025_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est year) cluster(est) 
outreg2 using out25.xls, append ctitle(gap boom crash +est year FE) addtext(est FE, YES) word excel label


* Bottom 75% isolation
reg f0075xf0075 year [aw=f0075_wn] if  f0075_wn>0, cluster(est)  
outreg2 using out75.xls, replace ctitle(Base) word excel label 

reg f0075xf0075 year i.nuts1 [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(Nuts1 FE) addtext(Nuts1 FE, YES) word excel label

reg f0075xf0075 year i.sector_agg [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(sector_agg FE) addtext(sector_agg FE, YES) word excel label

reg f0075xf0075 year i.orgsize [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(size FE) addtext(Orgsize FE, YES) word excel label

reg f0075xf0075 year i.nuts1 i.nuts1#c.f0075_nuts1 [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(Nuts1 exposure) addtext(Nuts1 FE, YES) word excel label

reg f0075xf0075 year i.nuts1 i.nuts1#c.f0075_nuts1 i.nuts1#c.year [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(Nuts1 variation) addtext(Nuts1 FE, YES) word excel label

reg f0075xf0075 year i.sector_agg i.sector_agg#c.f0075_sec [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(sector_agg exposure) addtext(sector_agg FE, YES) word excel label

reg f0075xf0075 year i.sector_agg i.sector_agg#c.f0075_sec i.sector_agg#c.year [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(sector_agg variation) addtext(sector_agg FE, YES) word excel label

reg f0075xf0075 year i.orgsize i.orgsize#c.f0075_sz [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(size exposure) addtext(Orgsize FE, YES) word excel label

reg f0075xf0075 year i.orgsize i.orgsize#c.f0075_sz i.orgsize#c.year [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(size variation) addtext(Orgsize FE, YES) word excel label

reg f0075xf0075 year i.nuts1 i.sector_agg i.orgsize [aw=f0075_wn] if  f0075_wn>0, cluster(est) 
outreg2 using out75.xls, append ctitle(3 gross FE) addtext(Nuts1 FE, YES, sector_agg FE, YES, Orgsize FE, YES) word excel label

reg f0075xf0075 year i.nuts1 i.nuts1#c.f0075_nuts1 i.sector_agg i.sector_agg#c.f0075_sec ///
	i.orgsize i.orgsize#c.f0075_sz [aw=f0075_wn] if  f0075_wn>0, cluster(est)  
outreg2 using out75.xls, append ctitle(3 gross exp) addtext(Nuts1 FE, YES, sector_agg FE, YES, Orgsize FE, YES) word excel label

reghdfe f0075xf0075 year [aw=f0075_wn] if  f0075_wn>0, abs(nuts3) cluster(est) 
outreg2 using out75.xls, append ctitle(nuts3 FE) addtext(Nuts3 FE, YES) word excel label

reghdfe f0075xf0075 year [aw=f0075_wn] if  f0075_wn>0, abs(sector) cluster(est) 
outreg2 using out75.xls, append ctitle(4D sec FE) addtext(4D sector FE, YES) word excel label

reghdfe f0075xf0075 year [aw=f0075_wn] if  f0075_wn>0, abs(est) cluster(est) 
outreg2 using out75.xls, append ctitle(est FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075 year lnnbwkrs [aw=f0075_wn] if  f0075_wn>0, abs(est) cluster(est) 
outreg2 using out75.xls, append ctitle(size +est FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075 year lnnbwkrs_cumpos lnnbwkrs_cumneg [aw=f0075_wn] if  f0075_wn>0, abs(est) cluster(est) 
outreg2 using out75.xls, append ctitle(asym size +est FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075 year lnnbwkrs lnnbwkrs_cumneg [aw=f0075_wn] if  f0075_wn>0, abs(est) cluster(est) 
outreg2 using out75.xls, append ctitle(asym size2 +est FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075 year lnwage_mu [aw=f0075_wn] if  f0075_wn>0, abs(est) cluster(est) 
outreg2 using out75.xls, append ctitle(wage+est FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075 year lnnbwkrs lnwage_mu [aw=f0075_wn] if  f0075_wn>0, abs(est) cluster(est) 
outreg2 using out75.xls, append ctitle(size+wage+est FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075 year empl_boom empl_crash [aw=f0075_wn] if  f0075_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est) cluster(est) 
outreg2 using out75.xls, append ctitle(boom crash +est FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075 lnnbwkrs [aw=f0075_wn] if  f0075_wn>0, abs(est year) cluster(est) 
outreg2 using out75.xls, append ctitle(size +est year FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075 empl_boom empl_crash [aw=f0075_wn] if  f0075_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est year) cluster(est) 
outreg2 using out75.xls, append ctitle(boom crash +est year FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075_gap lnnbwkrs [aw=f0075_wn] if  f0075_wn>0, abs(est year) cluster(est) 
outreg2 using out75.xls, append ctitle(gap size +est year FE) addtext(est FE, YES) word excel label

reghdfe f0075xf0075_gap empl_boom empl_crash [aw=f0075_wn] if  f0075_wn>0 & l2nbwkrs>0 & l2nbwkrs !=. & nbwkrs>50, abs(est year) cluster(est) 
outreg2 using out75.xls, append ctitle(gap boom crash +est year FE) addtext(est FE, YES) word excel label


* End new*
********************************
